Repository navigation
Conversation
greenhat
requested review from
Firestar99,
LegNeato and
eddyb
as code owners
November 16, 2026 13:27
greenhat
force-pushed
the
fix-memset-first-field
branch
from
November 16, 2026 13:37
2ae7348 to
e43a869
Compare
`rustc` lowers `[v; N]` to `memset` when all bytes of `v` are equal. For a destination at offset 0 of a bigger aggregate (`s.arr = [0; 4]`, `table[0] = [0.0; 3]`), the pointer still has the whole aggregate as its pointee type, so the store count was 0 and nothing was written. `memset` now looks for the field or element of the fill's size first, with `adjust_pointer_for_sized_access`, like `memcpy`, and returns early for a size of 0. If there is no such field or element and the size is not a multiple of the pointee size (e.g. the smaller field of a union), the fill is an error instead of being ignored.
greenhat
force-pushed
the
fix-memset-first-field
branch
from
November 16, 2026 16:00
e43a869 to
f3be8df
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A repeat array assigned to the first field of a struct, or to the first element of an array of arrays, writes nothing in a shader:
There is no error and no warning.
memset(builder/builder_methods.rs) now adjusts the destination withadjust_pointer_for_sized_access, likememcpydoes. A fill that still cannot be done (e.g. the smaller field of aunion) is a compile error instead of being ignored.The new difftest
lang/core/array/fill_offset_zerofails without the fix. The compiletestinit_array_union_fieldcovers the error.The fix and the tests were written with an AI coding agent. I reviewed and checked it.
Details
The code emitted for
resetbefore the fix:After:
Only the fills that
rustclowers tomemsetare affected: a constant whose bytes are all equal (0,0.0,u32::MAX) or a run-timeu8.[1; 4], element 1 instead of element 0, and a struct whose only field is the array were right before.The code emitted for a fill of a whole variable and for a fill at a non-zero offset does not change. For a struct whose only field is the array, the
OpStorenow takes the array constant directly, without theOpCompositeExtractandOpCompositeConstructsequence before it. The shader modules of the other difftests are byte-identical.The struct cases were a compile error (
memset on structs not implemented yet) before e3a26ef. I checked it by reverting that change locally. The array of arrays case wrote nothing before it as well.The error for the
unioncase:I used
self.errfor it, likememsetdoes for unsupported flags. Let me know if you prefer a zombie there.memsetwith a size of 0 now returns early, likememcpy.memsetwith a run-time size (memset_dynamic_size) is not changed.I ran the difftest on lavapipe only.